package com.example.yyjc.service.impl;

import com.example.yyjc.domain.countryanalyze.*;
import com.example.yyjc.domain.industryanalyze.*;
import com.example.yyjc.domain.selectionanalyze.CountrySecondCatCase;
import com.example.yyjc.mapper.ImportMapper;
import com.example.yyjc.service.ImportService;
import com.example.yyjc.util.ResultBean;
import com.example.yyjc.util.excel.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

/**
 * @ClassName ImportServiceImpl
 * @Description TODO
 * @Author lvyongwei
 * @Date 2021-02-24 13:22
 **/
@Service
public class ImportServiceImpl implements ImportService {

    @Autowired
    private ImportMapper importMapper;

    @Autowired
    private ExcelUtils excelUtils;

    private final String[] ORDERCOUNTLIMIT = {"1~10","11~50","51~100","100以上"};

    private final String[] PRICECOUNTLIMIT = {"0.00~10.00","11.00~50.00","51.00~100.00","100.00以上"};

    private final String[] PRICESECTION = {"0~5","5~20","20~50","50元以上"};

    private final String[] ORDERSECTION = {"0~50","50~100","100~200","200以上"};

    /**
     * 导入全部国家及日期信息
     * @param file
     * @return
     */
    @Override
    public ResultBean importCountry(MultipartFile file) {
        /**
         * 记录失败信息
         */
        StringBuilder failureMsg = new StringBuilder();

        /**
         * 记录成功信息
         */
        StringBuilder successMsg = new StringBuilder();

        /**
         * 记录成功条数
         */
        int failCount = 0;

        /**
         * 记录失败条数
         */
        int successCount = 0;
        /**
         * 获取到导入信息
         */
        List<Object> list = null;
        list = excelUtils.upload(file, Country.class);
        if(StringUtils.isEmpty(list) || list.size() == 0){
            return ResultBean.error("请按照模板要求填写导入信息,再进行导入");
        }
        for(Object o:list){
            Country country = (Country) o;
            try{
                if(!StringUtils.isEmpty(country)){
                    /**
                     * 调用插入方法
                     */
                    importMapper.importCountry(country);
                    /**
                     * 导入成功记录
                     */
                    successCount ++;
                    successMsg.append("<br/>" + successCount + "、国家" + country.getCountryName() + " : "+ country.getCreateTime() +  " 导入成功");
                }else{
                    failCount++;
                    failureMsg.append("<br/>" + failCount + "、国家" + country.getCountryName() + " : "+ country.getCreateTime() +  " 导入失败");
                }
            }catch (Exception e){
                e.printStackTrace();
                failCount++;
                String msg = "<br/>" + failCount + "、国家 " + country.getCountryName() + " : "+ country.getCreateTime() + " 导入失败";
                failureMsg.append(msg);
            }
        }
        if (failCount > 0)
        {
            failureMsg.insert(0, "很抱歉，导入失败！共 " + failCount + " 条数据格式不正确，错误如下：");
            return ResultBean.error(failureMsg.toString());
        }
        else
        {
            successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successCount + " 条，数据如下：");
            return ResultBean.success(successMsg.toString());
        }
    }

    /**
     * 导入商品订单数量占比
     * @param file
     * @return
     */
    @Override
    public ResultBean importOrderCountAnalysis(MultipartFile file) {
        /**
         * 记录失败信息
         */
        StringBuilder failureMsg = new StringBuilder();

        /**
         * 记录成功信息
         */
        StringBuilder successMsg = new StringBuilder();

        /**
         * 记录成功条数
         */
        int failCount = 0;

        /**
         * 记录失败条数
         */
        int successCount = 0;
        /**
         * 获取到导入信息
         */
        List<Object> orderCountAnalyses = excelUtils.upload(file, OrderCountAnalysis.class);
        if(StringUtils.isEmpty(orderCountAnalyses) || orderCountAnalyses.size() == 0){
            return ResultBean.error("请按照模板要求填写导入信息,再进行导入");
        }
        /**
         * 判断导入的信息是否正确
         */
        for(Object o:orderCountAnalyses) {
            OrderCountAnalysis orderCountAnalysis = (OrderCountAnalysis) o;
            if(Arrays.asList(ORDERCOUNTLIMIT).contains(orderCountAnalysis.getOrderCountLimit()) == false){
                return ResultBean.error("导入数据出错,请检查订单区间是否与导出的内容相同");
            }
        }
        for(Object o:orderCountAnalyses){
            OrderCountAnalysis orderCountAnalysis = (OrderCountAnalysis) o;
            try{
                if(!StringUtils.isEmpty(orderCountAnalysis)){
                    /**
                     * 调用插入方法
                     */
                    importMapper.importOrderCountAnalysis(orderCountAnalysis);
                    /**
                     * 导入成功记录
                     */
                    successCount ++;
                    successMsg.append("<br/>" + successCount + "、国家" + orderCountAnalysis.getCountryName() + " : "+ orderCountAnalysis.getCreateTime() + " : " + orderCountAnalysis.getOrderCountLimit() +  " 导入成功");
                }else{
                    failCount++;
                    failureMsg.append("<br/>" + failCount + "、国家" + orderCountAnalysis.getCountryName() + " : "+ orderCountAnalysis.getCreateTime() + " :  "+ orderCountAnalysis.getOrderCountLimit() +  " 导入失败");
                }
            }catch (Exception e){
                if(e instanceof DuplicateKeyException){
                    String msg = "<br/>" + failCount + "、国家 " + orderCountAnalysis.getCountryName() + " : "+ orderCountAnalysis.getCreateTime() + " :  "+ orderCountAnalysis.getOrderCountLimit() + " 导入失败,导入的国家及其日期且订单区间已存在,请审查";
                    failureMsg.append(msg);
                }else{
                    String msg = "<br/>" + failCount + "、国家 " + orderCountAnalysis.getCountryName() + " : "+ orderCountAnalysis.getCreateTime() + " :  "+ orderCountAnalysis.getOrderCountLimit() + " 导入失败";
                    failureMsg.append(msg);
                }
                e.printStackTrace();
                failCount++;
            }
        }
        if (failCount > 0)
        {
            failureMsg.insert(0, "很抱歉，导入失败！共 " + failCount + " 条数据格式不正确，错误如下：");
            return ResultBean.error(failureMsg.toString());
        }
        else
        {
            successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successCount + " 条，数据如下：");
            return ResultBean.success(successMsg.toString());
        }
    }

    /**
     * 导入商品价格区间信息占比
     * @param file
     * @return
     */
    @Override
    public ResultBean importPriceCountAnalysis(MultipartFile file) {
        /**
         * 记录失败信息
         */
        StringBuilder failureMsg = new StringBuilder();

        /**
         * 记录成功信息
         */
        StringBuilder successMsg = new StringBuilder();

        /**
         * 记录成功条数
         */
        int failCount = 0;

        /**
         * 记录失败条数
         */
        int successCount = 0;
        /**
         * 获取到导入信息
         */
        List<Object> priceCountAnalyses = excelUtils.upload(file, PriceCountAnalysis.class);
        if(StringUtils.isEmpty(priceCountAnalyses) || priceCountAnalyses.size() == 0){
            return ResultBean.error("请按照模板要求填写导入信息,再进行导入");
        }
        /**
         * 判断导入的信息是否正确
         */
        for(Object o:priceCountAnalyses) {
            PriceCountAnalysis priceCountAnalysis = (PriceCountAnalysis) o;
            if(Arrays.asList(PRICECOUNTLIMIT).contains(priceCountAnalysis.getPriceCountLimit()) == false){
                return ResultBean.error("导入数据出错,请检查价格区间是否与导出的内容相同");
            }
        }
        for(Object o:priceCountAnalyses){
            PriceCountAnalysis priceCountAnalysis = (PriceCountAnalysis) o;
            try{
                if(!StringUtils.isEmpty(priceCountAnalysis)){
                    /**
                     * 调用插入方法
                     */
                    importMapper.importPriceCountAnalysis(priceCountAnalysis);
                    /**
                     * 导入成功记录
                     */
                    successCount ++;
                    successMsg.append("<br/>" + successCount + "、国家" + priceCountAnalysis.getCountryName() + " : "+ priceCountAnalysis.getCreateTime() + " : " + priceCountAnalysis.getPriceCountLimit() +  " 导入成功");
                }else{
                    failCount++;
                    failureMsg.append("<br/>" + failCount + "、国家" + priceCountAnalysis.getCountryName() + " : "+ priceCountAnalysis.getCreateTime() + " :  "+ priceCountAnalysis.getPriceCountLimit() +  " 导入失败");
                }
            }catch (Exception e){
                if(e instanceof DuplicateKeyException){
                    String msg = "<br/>" + failCount + "、国家 " + priceCountAnalysis.getCountryName() + " : "+ priceCountAnalysis.getCreateTime() + " :  "+ priceCountAnalysis.getPriceCountLimit() + " 导入失败,导入的国家及其日期且价格区间已存在,请审查";
                    failureMsg.append(msg);
                }else{
                    String msg = "<br/>" + failCount + "、国家 " + priceCountAnalysis.getCountryName() + " : "+ priceCountAnalysis.getCreateTime() + " :  "+ priceCountAnalysis.getPriceCountLimit() + " 导入失败";
                    failureMsg.append(msg);
                }
                failCount++;
            }
        }
        if (failCount > 0)
        {
            failureMsg.insert(0, "很抱歉，导入失败！共 " + failCount + " 条数据格式不正确，错误如下：");
            return ResultBean.error(failureMsg.toString());
        }
        else
        {
            successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successCount + " 条，数据如下：");
            return ResultBean.success(successMsg.toString());
        }
    }

    /**
     * 导入各个国家每个月份一级类目占比
     * @param file
     * @return
     */
    @Override
    public ResultBean importMainTitleScale(MultipartFile file) {
        /**
         * 记录失败信息
         */
        StringBuilder failureMsg = new StringBuilder();

        /**
         * 记录成功信息
         */
        StringBuilder successMsg = new StringBuilder();

        /**
         * 记录成功条数
         */
        int failCount = 0;

        /**
         * 记录失败条数
         */
        int successCount = 0;
        /**
         * 获取到导入信息
         */
        List<Object> mainTitleScales = excelUtils.upload(file, MainTitleScale.class);
        if(StringUtils.isEmpty(mainTitleScales) || mainTitleScales.size() == 0){
            return ResultBean.error("请按照模板要求填写导入信息,再进行导入");
        }
        for(Object o:mainTitleScales){
            MainTitleScale mainTitleScale = (MainTitleScale) o;
            try{
                if(!StringUtils.isEmpty(mainTitleScale)){
                    /**
                     * 调用插入方法
                     */
                    importMapper.importMainTitleScale(mainTitleScale);
                    /**
                     * 导入成功记录
                     */
                    successCount ++;
                    successMsg.append("<br/>" + successCount + "、国家" + mainTitleScale.getCountryName() + " : "+ mainTitleScale.getCreateTime() + " : "+ mainTitleScale.getMainTitle() +  " 导入成功");
                }else{
                    failCount++;
                    failureMsg.append("<br/>" + failCount + "、国家" + mainTitleScale.getCountryName() + " : "+ mainTitleScale.getCreateTime() + " : "+ mainTitleScale.getMainTitle() +  " 导入失败");
                }
            }catch (Exception e){
                if(e instanceof DuplicateKeyException){
                    String msg = "<br/>" + failCount + "、国家 " + mainTitleScale.getCountryName() + " : "+ mainTitleScale.getCreateTime() + " : "+ mainTitleScale.getMainTitle() + " 导入失败,导入的国家及其日期下以及该类目已存在,请审查";
                    failureMsg.append(msg);
                }else{
                    String msg = "<br/>" + failCount + "、国家 " + mainTitleScale.getCountryName() + " : "+ mainTitleScale.getCreateTime() + " : "+ mainTitleScale.getMainTitle() + " 导入失败";
                    failureMsg.append(msg);
                }
                failCount++;
            }
        }
        if (failCount > 0)
        {
            failureMsg.insert(0, "很抱歉，导入失败！共 " + failCount + " 条数据格式不正确，错误如下：");
            return ResultBean.error(failureMsg.toString());
        }
        else
        {
            successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successCount + " 条，数据如下：");
            return ResultBean.success(successMsg.toString());
        }
    }

    /**
     * 导入国家各个月份物流订单
     * @param file
     * @return
     */
    @Override
    public ResultBean importLogisticsOrder(MultipartFile file) {
        /**
         * 记录失败信息
         */
        StringBuilder failureMsg = new StringBuilder();

        /**
         * 记录成功信息
         */
        StringBuilder successMsg = new StringBuilder();

        /**
         * 记录成功条数
         */
        int failCount = 0;

        /**
         * 记录失败条数
         */
        int successCount = 0;
        /**
         * 获取到导入信息
         */
        List<Object> logisticsOrders = excelUtils.upload(file, LogisticsOrder.class);
        if(StringUtils.isEmpty(logisticsOrders) || logisticsOrders.size() == 0){
            return ResultBean.error("请按照模板要求填写导入信息,再进行导入");
        }
        for(Object o:logisticsOrders){
            LogisticsOrder logisticsOrder = (LogisticsOrder) o;
            try{
                if(!StringUtils.isEmpty(logisticsOrder)){
                    /**
                     * 调用插入方法
                     */
                    importMapper.importLogisticsOrder(logisticsOrder);
                    /**
                     * 导入成功记录
                     */
                    successCount ++;
                    successMsg.append("<br/>" + successCount + "、国家" + logisticsOrder.getCountryName() + " : "+ logisticsOrder.getCreateTime() + " : "+ logisticsOrder.getLogisticsName() +  " 导入成功");
                }else{
                    failCount++;
                    failureMsg.append("<br/>" + failCount + "、国家" + logisticsOrder.getCountryName() + " : "+ logisticsOrder.getCreateTime() + " : "+ logisticsOrder.getLogisticsName() +  " 导入失败");
                }
            }catch (Exception e){
                if(e instanceof DuplicateKeyException){
                    String msg = "<br/>" + failCount + "、国家 " + logisticsOrder.getCountryName() + " : "+ logisticsOrder.getCreateTime() + " : "+ logisticsOrder.getLogisticsName() + " 导入失败,导入的国家及其日期下该物流名称已存在,请审查";
                    failureMsg.append(msg);
                }else{
                    String msg = "<br/>" + failCount + "、国家 " + logisticsOrder.getCountryName() + " : "+ logisticsOrder.getCreateTime() + " : "+ logisticsOrder.getLogisticsName() + " 导入失败";
                    failureMsg.append(msg);
                }
                failCount++;
            }
        }
        if (failCount > 0)
        {
            failureMsg.insert(0, "很抱歉，导入失败！共 " + failCount + " 条数据格式不正确，错误如下：");
            return ResultBean.error(failureMsg.toString());
        }
        else
        {
            successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successCount + " 条，数据如下：");
            return ResultBean.success(successMsg.toString());
        }
    }

    /**
     * 导入国家某个月份top100电铺
     * @param shopTopTens
     * @return
     */
    @Override
    public int importShopTopTen(List<ShopTopTen> shopTopTens) {
        return importMapper.importShopTopTen(shopTopTens);
    }

    /**
     * 导入国家某个月份top10商品
     * @param goodsTopTens
     * @return
     */
    @Override
    public int importGoodsTopTen(List<GoodsTopTen> goodsTopTens) {
        return importMapper.importGoodsTopTen(goodsTopTens);
    }

    /**
     * 导入国家每个月份top1店铺名称
     * @param file
     * @return
     */
    @Override
    public ResultBean importCountryTopOneShopName(MultipartFile file) {
        /**
         * 记录失败信息
         */
        StringBuilder failureMsg = new StringBuilder();

        /**
         * 记录成功信息
         */
        StringBuilder successMsg = new StringBuilder();

        /**
         * 记录成功条数
         */
        int failCount = 0;

        /**
         * 记录失败条数
         */
        int successCount = 0;
        List<Object> topOneShopNames = excelUtils.upload(file , CountryTopOneShopName.class);
        if(StringUtils.isEmpty(topOneShopNames) || topOneShopNames.size() == 0){
            return ResultBean.error("请按照模板要求填写导入信息,再进行导入");
        }
        for(Object o:topOneShopNames) {
            CountryTopOneShopName countryTopOneShopName = (CountryTopOneShopName) o;
            try{
                if(!StringUtils.isEmpty(countryTopOneShopName)){
                    /**
                     * 调用插入方法
                     */
                    importMapper.importCountryTopOneShopName(countryTopOneShopName);
                    /**
                     * 导入成功记录
                     */
                    successCount ++;
                    successMsg.append("<br/>" + successCount + "、国家" + countryTopOneShopName.getCountryName() + " : "+ countryTopOneShopName.getCreateTime() + " : "+ countryTopOneShopName.getTopOneShopName() +  " 导入成功");
                }else{
                    failCount++;
                    failureMsg.append("<br/>" + failCount + "、国家" + countryTopOneShopName.getCountryName() + " : "+ countryTopOneShopName.getCreateTime() + " : "+ countryTopOneShopName.getTopOneShopName() +  " 导入失败");
                }
            }catch (Exception e){
                e.printStackTrace();
                if(e instanceof DuplicateKeyException){
                    String msg = "<br/>" + failCount + "、国家 " + countryTopOneShopName.getCountryName() + " : "+ countryTopOneShopName.getCreateTime() + " : "+ countryTopOneShopName.getTopOneShopName() + " 导入失败,导入的国家及其日期已存在,请审查";
                    failureMsg.append(msg);
                }else{
                    String msg = "<br/>" + failCount + "、国家 " + countryTopOneShopName.getCountryName() + " : "+ countryTopOneShopName.getCreateTime() + " : "+ countryTopOneShopName.getTopOneShopName() + " 导入失败";
                    failureMsg.append(msg);
                }
                failCount++;
            }
        }
        if (failCount > 0)
        {
            failureMsg.insert(0, "很抱歉，导入失败！共 " + failCount + " 条数据格式不正确，错误如下：");
            return ResultBean.error(failureMsg.toString());
        }
        else
        {
            successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successCount + " 条，数据如下：");
            return ResultBean.success(successMsg.toString());
        }
    }

    /**
     * 导入国家的top1店铺所有商品信息
     * @param file
     * @return
     */
    @Override
    public ResultBean importCountryToponeShopMsg(MultipartFile file) {
        List<Object> countryToponeShopMsgs = excelUtils.upload(file,CountryToponeShopMsg.class);
        /**
         * 获取所有的店铺名称
         */
        List<String> shopNames = importMapper.getShopNames();
        for(Object o:countryToponeShopMsgs){
            CountryToponeShopMsg countryToponeShopMsg = (CountryToponeShopMsg) o;
            if(shopNames.contains((countryToponeShopMsg.getShopName()))){
                return ResultBean.error("已经存在《"+countryToponeShopMsg.getShopName()+"》店铺，无需重复导入,请检查删除");
            }
        }
        List<CountryToponeShopMsg> countryToponeShopMsgList = (List) countryToponeShopMsgs;
        try{
            int count = importMapper.importCountryToponeShopMsg(countryToponeShopMsgList);
            return ResultBean.success("恭喜您，数据已全部导入成功！共 "+ count +" 条数据");
        }catch (Exception e){
            return ResultBean.error("导入失败,请重新查看是否符合要求");
        }
    }

    /**
     * 导入所有一级类目的每月的销售额
     * @param firstCatSales
     * @return
     */
    @Override
    public int importFirstCatSale(List<FirstCatSale> firstCatSales) {
        return importMapper.importFirstCatSale(firstCatSales);
    }

    /**
     * 导入所有二级类目的每月销售额
     * @param secondCatSales
     * @return
     */
    @Override
    public int importSecondCatSale(List<SecondCatSale> secondCatSales) {
        return importMapper.importSecondCatSale(secondCatSales);
    }

    /**
     * 导入二级类目各个月份各个国家销售额
     * @param secondCatCountrySaleCounts
     * @return
     */
    @Override
    public int importSecondCatCountrySaleCount(List<SecondCatCountrySaleCount> secondCatCountrySaleCounts) {
        return importMapper.importSecondCatCountrySaleCount(secondCatCountrySaleCounts);
    }

    /**
     * 导入二级类目每个月份国家物流订单量
     * @param deliveryCountries
     * @return
     */
    @Override
    public int importDeliveryCountry(List<DeliveryCountry> deliveryCountries) {
        return importMapper.importDeliveryCountry(deliveryCountries);
    }

    /**
     * 导入二级类目每个月份价格区间商品/订单数量
     * @param file
     * @return
     */
    @Override
    public ResultBean importSecondCatPriceScale(MultipartFile file) {
        /**
         * 记录失败信息
         */
        StringBuilder failureMsg = new StringBuilder();

        /**
         * 记录成功信息
         */
        StringBuilder successMsg = new StringBuilder();

        /**
         * 记录成功条数
         */
        int failCount = 0;

        /**
         * 记录失败条数
         */
        int successCount = 0;
        /**
         * 获取到导入信息
         */
        List<Object> secondCatPriceScales = excelUtils.upload(file, SecondCatPriceScale.class);
        if(StringUtils.isEmpty(secondCatPriceScales) || secondCatPriceScales.size() == 0){
            return ResultBean.error("请按照模板要求填写导入信息,再进行导入");
        }
        /**
         * 判断导入的信息是否正确
         */
        for(Object o:secondCatPriceScales) {
            SecondCatPriceScale secondCatPriceScale = (SecondCatPriceScale) o;
            if(Arrays.asList(PRICESECTION).contains(secondCatPriceScale.getPriceSection()) == false){
                return ResultBean.error("导入数据出错,请检查价格区间是否与导出的内容相同");
            }
        }
        for(Object o:secondCatPriceScales){
            SecondCatPriceScale secondCatPriceScale = (SecondCatPriceScale) o;
            try{
                if(!StringUtils.isEmpty(secondCatPriceScale)){
                    /**
                     * 调用插入方法
                     */
                    importMapper.importSecondCatPriceScale(secondCatPriceScale);
                    /**
                     * 导入成功记录
                     */
                    successCount ++;
                    successMsg.append("<br/>" + successCount + "、二级类目:" + secondCatPriceScale.getSecondCatId() + " : "+ secondCatPriceScale.getCreateTime() + " : " + secondCatPriceScale.getPriceSection() +  " 导入成功");
                }else{
                    failCount++;
                    failureMsg.append("<br/>" + failCount + "、二级类目:" + secondCatPriceScale.getSecondCatId() + " : "+ secondCatPriceScale.getCreateTime() + " : " + secondCatPriceScale.getPriceSection() +  " 导入失败");
                }
            }catch (Exception e){
                if(e instanceof DuplicateKeyException){
                    String msg = "<br/>" + failCount + "、二级类目:" + secondCatPriceScale.getSecondCatId() + " : "+ secondCatPriceScale.getCreateTime() + " : " + secondCatPriceScale.getPriceSection() + " 导入失败,该二级类目时间下该区间已存在,请审查";
                    failureMsg.append(msg);
                }else{
                    String msg = "<br/>" + failCount + "、二级类目:" + secondCatPriceScale.getSecondCatId() + " : "+ secondCatPriceScale.getCreateTime() + " : " + secondCatPriceScale.getPriceSection() + " 导入失败";
                    failureMsg.append(msg);
                }
                failCount++;
            }
        }
        if (failCount > 0)
        {
            failureMsg.insert(0, "很抱歉，导入失败！共 " + failCount + " 条数据格式不正确，错误如下：");
            return ResultBean.error(failureMsg.toString());
        }
        else
        {
            successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successCount + " 条，数据如下：");
            return ResultBean.success(successMsg.toString());
        }
    }

    /**
     * 导入二级类目每个月份订单区间商品/订单数量
     * @param file
     * @return
     */
    @Override
    public ResultBean importSecondCatOrderScale(MultipartFile file) {
        /**
         * 记录失败信息
         */
        StringBuilder failureMsg = new StringBuilder();

        /**
         * 记录成功信息
         */
        StringBuilder successMsg = new StringBuilder();

        /**
         * 记录成功条数
         */
        int failCount = 0;

        /**
         * 记录失败条数
         */
        int successCount = 0;
        /**
         * 获取到导入信息
         */
        List<Object> secondCatOrderScales = excelUtils.upload(file, SecondCatOrderScale.class);
        if(StringUtils.isEmpty(secondCatOrderScales) || secondCatOrderScales.size() == 0){
            return ResultBean.error("请按照模板要求填写导入信息,再进行导入");
        }
        /**
         * 判断导入的信息是否正确
         */
        for(Object o:secondCatOrderScales) {
            SecondCatOrderScale secondCatOrderScale = (SecondCatOrderScale) o;
            if(Arrays.asList(ORDERSECTION).contains(secondCatOrderScale.getOrderSection()) == false){
                return ResultBean.error("导入数据出错,请检查价格区间是否与导出的内容相同");
            }
        }
        for(Object o:secondCatOrderScales){
            SecondCatOrderScale secondCatOrderScale = (SecondCatOrderScale) o;
            try{
                if(!StringUtils.isEmpty(secondCatOrderScale)){
                    /**
                     * 调用插入方法
                     */
                    importMapper.importSecondCatOrderScale(secondCatOrderScale);
                    /**
                     * 导入成功记录
                     */
                    successCount ++;
                    successMsg.append("<br/>" + successCount + "、二级类目:" + secondCatOrderScale.getSecondCatId() + " : "+ secondCatOrderScale.getCreateTime() + " : " + secondCatOrderScale.getOrderSection() +  " 导入成功");
                }else{
                    failCount++;
                    failureMsg.append("<br/>" + failCount + "、二级类目:" + secondCatOrderScale.getSecondCatId() + " : "+ secondCatOrderScale.getCreateTime() + " : " + secondCatOrderScale.getOrderSection() +  " 导入失败");
                }
            }catch (Exception e){
                if(e instanceof DuplicateKeyException){
                    String msg = "<br/>" + failCount + "、二级类目:" + secondCatOrderScale.getSecondCatId() + " : "+ secondCatOrderScale.getCreateTime() + " : " + secondCatOrderScale.getOrderSection() + " 导入失败,该二级类目时间下该区间已存在,请审查";
                    failureMsg.append(msg);
                }else{
                    String msg = "<br/>" + failCount + "、二级类目:" + secondCatOrderScale.getSecondCatId() + " : "+ secondCatOrderScale.getCreateTime() + " : " + secondCatOrderScale.getOrderSection() + " 导入失败";
                    failureMsg.append(msg);
                }
                failCount++;
            }
        }
        if (failCount > 0)
        {
            failureMsg.insert(0, "很抱歉，导入失败！共 " + failCount + " 条数据格式不正确，错误如下：");
            return ResultBean.error(failureMsg.toString());
        }
        else
        {
            successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successCount + " 条，数据如下：");
            return ResultBean.success(successMsg.toString());
        }
    }

    /**
     * 导入二级类目每个月top10店铺信息
     * @param secondCatShopTopTens
     * @return
     */
    @Override
    public int importSecondCatShopTopTen(List<SecondCatShopTopTen> secondCatShopTopTens) {
        return importMapper.importSecondCatShopTopTen(secondCatShopTopTens);
    }

    /**
     * 导入二级类目每个月top100商品信息
     * @param secondCatGoodsTopTens
     * @return
     */
    @Override
    public int importSecondCatGoodsTopTen(List<SecondCatGoodsTopTen> secondCatGoodsTopTens) {
        return importMapper.importSecondCatGoodsTopTen(secondCatGoodsTopTens);
    }

    /**
     * 导入二级类目每个月top10国家top3物流信息
     * @param secondCatTopLogistics
     * @return
     */
    @Override
    public int importSecondCatTopLogistics(List<SecondCatTopLogistics> secondCatTopLogistics) {
        return importMapper.importSecondCatTopLogistics(secondCatTopLogistics);
    }

    /**
     * 导入Aliexpress前10国家信息
     * @param aliexpresses
     * @return
     */
    @Override
    public int importAliexpress(List<Aliexpress> aliexpresses) {
        return importMapper.importAliexpress(aliexpresses);
    }

    /**
     * 导入Aliexpress的前10二级类目信息
     * @param aliexpressSecondCatTopTens
     * @return
     */
    @Override
    public int importAliexpressSecondCatTopTen(List<AliexpressSecondCatTopTen> aliexpressSecondCatTopTens) {
        return importMapper.importAliexpressSecondCatTopTen(aliexpressSecondCatTopTens);
    }

    /**
     * 导入国家每个月份二级类目情况
     * @param countrySecondCatCases
     * @return
     */
    @Override
    public int importCountrySecondCatCase(List<CountrySecondCatCase> countrySecondCatCases) {
        return importMapper.importCountrySecondCatCase(countrySecondCatCases);
    }
}